package edu.gatech.oad;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.SimpleAdapter;
import android.widget.Button;
import android.widget.ListView;

public class ManageOldUser extends Activity{
	public static ArrayList<User> UserList = new ArrayList<User>();
	public static boolean usersFiltered = false;;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		System.out.println("Trying to get this shit going");
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.manage_old_user);

		/*
		 * put data shit in here.
		 */
		System.out.println("Started ItemList Activity");
		DataBaseHelper data = new DataBaseHelper(getApplicationContext());
		try {
			data.createDataBase();
			data.openDataBase();
		} catch (Exception E) {
			// do nothing
		}
		System.out.println("DB Created");
		ListView listView = (ListView) findViewById(R.id.UserList);
		
		// Bundle b = getIntent().getExtras();
		// String status = "Lost";
		// System.out.println(status + " ItemList.java");
		// lost = 0; found = 1
		/*
		 * if (status.equals("Lost")) { for (Item item : data.getItems()) {
		 * //change to get only lost items items.add(item.getItemDescription());
		 * } } else { for (Item item : data.getItems()) { //change to get only
		 * found items items.add(item.getItemDescription()); } }
		 */
		if (!usersFiltered) {
			for (User u : data.getUsers("all")) {
				// change to get only found items
				UserList.add(u);
			}
		}
		
		// Define a new Adapter
		// First parameter - Context
		// Second parameter - Layout for the row
		// Third parameter - ID of the TextView to which the data is written
		// Forth - the Array of data
		//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				//android.R.layout.simple_list_item_1, android.R.id.text1,
				//MainActivity.gblItemList);
		//SimpleAdapter adapter = new SimpleAdapter(this,MainActivity.gblItemList, android.R.layout.simple_list_item_2, android.R.id.text1);
		List<Map<String, String>> users = new ArrayList<Map<String, String>>();
		for(User u :UserList){
			Map<String, String> datum = new HashMap<String, String>(2);
		    datum.put("title", u.un);
		    datum.put("other", u.AccountStatus);
		    users.add(datum);
		}
		SimpleAdapter adapter = new SimpleAdapter(this, users,
				android.R.layout.simple_list_item_2,
                new String[] {"title", "other"},
                new int[] {android.R.id.text1,
                           android.R.id.text2});
		// Assign adapter to ListView
		listView.setAdapter(adapter);
		usersFiltered = false;

		Button filterButton = (Button) findViewById(R.id.filterUsers);
		filterButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent b = new Intent(ManageOldUser.this, FindUser.class);
				startActivity(b);

			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.item_list, menu);
		return true;
	}
}
